package com.goods.controller.business;

import com.goods.business.service.HealthService;
import com.goods.common.model.business.Health;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.ListPageUtils;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "健康打卡")
@RestController
@RequestMapping("business/health")
public class HealthController {
    @Resource
    private HealthService healthService;
    @GetMapping("/isReport")
    public ResponseBean isReport(){
        boolean report = healthService.isReport();
        if (report){
            return ResponseBean.success(true);
        }else {
            return ResponseBean.success(false);
        }
    }
    @PostMapping("/report")
    public ResponseBean report(@RequestBody Health health){
        Integer integer = healthService.report(health);
        return ResponseBean.success();
    }
    @GetMapping("/history")
    private ResponseBean getHistory(Integer pageSize,Integer pageNum){
        List<Health> list = healthService.getHistory();
        Integer total = list.size();
        if (!CollectionUtils.isEmpty(list)){
            list = ListPageUtils.page(list, pageSize, pageNum);
        }
        PageVO<Health> pageVO = new PageVO<>(total, list);
        return ResponseBean.success(pageVO);
    }
}
